<?php
class WechatController extends WechatAppController{
	
	public function beforeFilter(){
	    $this->Auth->allow('index','factory','emoji');
		parent::beforeFilter();
	}
	
	public function admin_index(){
	
	}

	public function emoji(){}
	
    public function factory(){
    	$options = array(
			'token'=>Configure::read("Wechat.token"), //填写你设定的key
    		'encodingaeskey'=>Configure::read("Wechat.encodingaeskey"), //填写加密用的EncodingAESKey
    		'appid'=>Configure::read("Wechat.appID"), //填写高级调用功能的app id
    		'appsecret'=>Configure::read("Wechat.appsecret") //填写高级调用功能的密钥
		);
    	App::import('Vendor','Wechat.WechatSDK',array('file'=>'wxmsg'.DS.'wechat.class.php'));
    	$WechatSDK = new WechatSDK($options);
    	$WechatSDK->valid();
    	$type = $WechatSDK->getRev()->getRevType();
    	$data = $WechatSDK->getRevData();
    	//pr($type);
    	switch($type) {
    		case WechatSDK::MSGTYPE_EVENT:
    			$this->loadModel('Wechat.WxSubscribe');
    			if($data['Event'] == WechatSDK::EVENT_SUBSCRIBE){
	    			 
    			}else if($data['Event'] == WechatSDK::EVENT_UNSUBSCRIBE){
    				
    			}else if($data['Event'] == WechatSDK::EVENT_MENU_CLICK){
					 
					
				}
    			break;
    		case WechatSDK::MSGTYPE_IMAGE:
				break;
    		default:
    			//$WechatSDK->text("help info")->reply();
    			break;
		}
		exit;
    } 
	
	public function subornot(){
		//pr($this->Auth->user());
		exit;	
		//$this->redirect(array('plugin'=>false,'controller'=>'Index','action'=>'index'));
	}
}
